@echo off
set PRJ_NAME=ALL_FW
set AXF_DIR=.\%PRJ_NAME%_Data\VSN_V2_ROM
set AXF_NAME=%PRJ_NAME%.axf
set RAM_DIR=%AXF_DIR%
set PKG_DIR=%AXF_DIR%
set PKG_NAME=VSN_V2FW
set H_DIR=%AXF_DIR%
set OUT_DIR=c:\aitfw\82x

IF NOT EXIST %OUT_DIR% MD %OUT_DIR%

@echo on
::copy %OUT_DIR%\VSN_V2BC %PKG_DIR%\VSN_V2BC 
fromELF.exe -c -bin %AXF_DIR%\%AXF_NAME% -output %RAM_DIR%\ALL_DRAM
..\FirmwarePackager .\ldsfile_VSN_V2_flash.txt %RAM_DIR%\ %PKG_DIR%\%PKG_NAME% /q

@if errorlevel 1 (
  @echo.
  @echo Error on Packing FW
  @pause
  @goto :EOF )

:: Generate Vision flash image 
REM old
::..\VisionFlashImageGen 2 %PKG_DIR%\VSN_V2ROMFlashImage.bin %PKG_DIR%\VSN_V2BC %PKG_DIR%\%PKG_NAME% VSN_V2

REM new
::format: VisionFlashImageGen.exe ChipID outfile infileNum infile1 enable1 infile2 enable2...
..\VisionFlashImageGen VSN_V2 %PKG_DIR%\VSN_V2ROMFlashImage.bin 2 %PKG_DIR%\VSN_V2BC 1 %PKG_DIR%\%PKG_NAME% 1

@if errorlevel 1 ( 
  @echo.
  @echo Error on Generate FW image for ROM boot
  @pause
  @goto :EOF )

:: Use old FW packager to make UVC image.
::..\MergeFirmwarePackage 2 %PKG_DIR%\VSN_V2FWImage.bin %PKG_DIR%\VSN_V2BC %PKG_DIR%\%PKG_NAME%
..\MergeFirmwarePackage 1 %PKG_DIR%\VSN_V2FWROMImage.bin %PKG_DIR%\VSN_V2ROMFlashImage.bin

@if errorlevel 1 ( 
  @echo.
  @echo Error on Merging Packages
  @pause
  @goto :EOF )

@echo.
@echo This file is for UVC tools and Recovery Tool.
copy %PKG_DIR%\VSN_V2FWROMImage.bin %OUT_DIR%\VSN_V2FW_USB.bin
@if errorlevel 1 (
  @echo.
  @echo Error on Copying files
  @pause
  @goto :EOF )

@echo.
@echo This file is for ROM writter.
copy %PKG_DIR%\VSN_V2ROMFlashImage.bin %OUT_DIR%\VSN_V2FW_ROM.bin
copy %PKG_DIR%\VSN_V2BC %OUT_DIR%
copy %PKG_DIR%\VSN_V2FW %OUT_DIR%

::pause

